package com.bdqn.Di1Zhan;

import com.bdqn.Di1Zhan.entity.Person;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * 第一章实战1
 */
public class PersonSelect {
    public static void main(String[] args) {
        Class slz = Person.class;

        Field[] fields = Person.class.getDeclaredFields();

        Method[] methods = Person.class.getDeclaredMethods();

        String fullName = slz.getSimpleName();

        System.out.println("========类型信息=========");

        System.out.println("类名：" + fullName);

        int modifier = slz.getModifiers();

        if ((modifier & Modifier.PUBLIC) == Modifier.PUBLIC)
            System.out.println("修饰符是：public");
        else
            System.out.println("修饰符是：default(package)");

        Class[] interfaces = slz.getInterfaces();
        for (Class c : interfaces) {
            System.out.println("继承关系：" + c.getName());
        }

        System.out.println("------------------------------------");

        for (Field fieId : fields) {
            System.out.println("属性名：" + fieId.getName());
            System.out.println("类型：" + fieId.getType().getName());
            System.out.print("修饰符：");
            int modifiers = fieId.getModifiers();
            if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC)
                System.out.println("public");
            else if ((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED)
                System.out.println("public");
            else if ((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE)
                System.out.println("public");
            else
                System.out.println("default(package)");
            System.out.println("===============================");
        }

        System.out.println("--------------------------------------");

        for (Method method : methods) {
            System.out.println("方法名：" + method.getName());
            System.out.println("返回值类型：" + method.getReturnType().getName());

            Class[] params = method.getParameterTypes();
            if (params.length == 0) {
                System.out.println("该方法没有参数");
            } else {
                System.out.println("该方法的参数列表为：[");
                for (int i = 0; i < params.length; i++) {
                    System.out.println(params[i].getName());
                }
                System.out.println("]");
            }
            System.out.println("访问修饰符：");
            int modifiers = method.getModifiers();
            if (((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC))
                System.out.println("public");
            else if ((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED)
                System.out.println("protected");
            else if ((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE)
                System.out.println("private");
            else
                System.out.println("default(package)");
            System.out.println("===============================");
        }
    }
}
